class Solution(object):
    def maxRotateFunction(self, nums):
        """
        :type nums: List[int]
        :rtype: int
        """
        total = sum(nums)
        n = len(nums)
        DP = [0] * n
        for i in range(n):
            DP[0] += i * nums[i]
        for i in range(1, n):
            DP[i] = DP[i - 1] + total - n * nums[n - i]
        return max(DP)


data = Solution()
nums = [4, 3, 2, 6]
print(data.maxRotateFunction(nums))
